<template>
  <el-aside width="250px" class="sidebar">
    <div class="logo">
      <h2>南通大学</h2>
      <p>管理后台</p>
    </div>
    
    <el-menu
      :default-active="activeTab"
      class="sidebar-menu"
      @select="handleMenuSelect"
    >
      <el-menu-item index="hierarchy">
        <el-icon><Operation /></el-icon>
        <span>层级管理</span>
      </el-menu-item>
      <el-menu-item index="pages">
        <el-icon><Document /></el-icon>
        <span>页面管理</span>
      </el-menu-item>
      <el-menu-item index="categories">
        <el-icon><Folder /></el-icon>
        <span>分类管理</span>
      </el-menu-item>
      <el-menu-item index="items">
        <el-icon><List /></el-icon>
        <span>项目管理</span>
      </el-menu-item>
      <el-menu-item index="quill-editor">
        <el-icon><Edit /></el-icon>
        <span>Quill 编辑器</span>
      </el-menu-item>
    </el-menu>
    
    <!-- 用户信息和退出登录 -->
    <div class="user-section">
      <div class="user-info">
        <el-icon><User /></el-icon>
        <span>{{ userInfo?.name || userInfo?.username || '管理员' }}</span>
      </div>
      <el-button 
        type="danger" 
        size="small" 
        @click="handleLogout"
        class="logout-btn"
      >
        <el-icon><Close /></el-icon>
        退出登录
      </el-button>
    </div>
  </el-aside>
</template>

<script setup>
import {
  Document,
  Folder,
  List,
  Operation,
  Edit,
  Close,
  User
} from '@element-plus/icons-vue'

// Props
defineProps({
  activeTab: {
    type: String,
    required: true
  },
  userInfo: {
    type: Object,
    default: () => ({})
  }
})

// Emits
const emit = defineEmits(['menu-select', 'logout'])

const handleMenuSelect = (index) => {
  emit('menu-select', index)
}

const handleLogout = () => {
  emit('logout')
}
</script>

<style scoped>
.sidebar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  height: 100vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(20px);
  border-right: 1px solid rgba(255, 255, 255, 0.2);
}

.logo {
  padding: 20px;
  text-align: center;
  border-bottom: 1px solid #434a5a;
}

.logo h2 {
  margin: 0 0 5px 0;
  font-size: 18px;
  font-weight: 600;
}

.logo p {
  margin: 0;
  font-size: 12px;
  opacity: 0.8;
}

.sidebar-menu {
  flex: 1;
  border: none;
  background-color: transparent;
}

.sidebar-menu .el-menu-item {
  color: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  margin: 6px 16px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-weight: 600;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-menu .el-menu-item:hover {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  transform: translateX(4px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.sidebar-menu .el-menu-item.is-active {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.user-section {
  padding: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  margin: 12px;
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.user-info {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  color: #bfcbd9;
}

.user-info .el-icon {
  margin-right: 8px;
}

.logout-btn {
  width: 100%;
  margin-top: 16px;
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%) !important;
  border: none !important;
  border-radius: 12px !important;
  padding: 12px 20px !important;
  font-weight: 600 !important;
  box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3) !important;
  transition: all 0.3s ease !important;
}

.logout-btn:hover {
  background: linear-gradient(135deg, #ff5252 0%, #e53e3e 100%) !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4) !important;
}
</style>